﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdFdFieldEngine : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdFdFieldEngine(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdFdFieldEngine_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdFdFieldEngine obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdFdFieldEngine()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdFdFieldEngine(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdFdFieldEngine cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdFdFieldEngine_cast(OdRxObject.getCPtr(pObj));
			OdFdFieldEngine result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdFdFieldEngine)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdFdFieldEngine)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdFdFieldEngine)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdFdFieldEngine_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdFdFieldEngine_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdFdFieldEngine_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdFdFieldEngine createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdFdFieldEngine_createObject();
			OdFdFieldEngine result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdFdFieldEngine)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdFdFieldEngine)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdFdFieldEngine)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void registerEvaluatorLoader(OdFdFieldEvaluatorLoader pLoader)
		{
			TD_DbPINVOKE.OdFdFieldEngine_registerEvaluatorLoader(this.swigCPtr, OdFdFieldEvaluatorLoader.getCPtr(pLoader));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void unregisterEvaluatorLoader(OdFdFieldEvaluatorLoader pLoader)
		{
			TD_DbPINVOKE.OdFdFieldEngine_unregisterEvaluatorLoader(this.swigCPtr, OdFdFieldEvaluatorLoader.getCPtr(pLoader));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual int evaluatorLoaderCount()
		{
			int result = TD_DbPINVOKE.OdFdFieldEngine_evaluatorLoaderCount(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdFdFieldEvaluatorLoader getEvaluatorLoader(int inputIndex)
		{
			OdFdFieldEvaluatorLoader result = (OdFdFieldEvaluatorLoader)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdFdFieldEngine_getEvaluatorLoader(this.swigCPtr, inputIndex), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdFdFieldEvaluator getEvaluator(string pszEvalId)
		{
			OdFdFieldEvaluator result = (OdFdFieldEvaluator)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdFdFieldEngine_getEvaluator(this.swigCPtr, pszEvalId), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdFdFieldEvaluator findEvaluator(OdDbField pField, ref string pszEvalId)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(pszEvalId);
			IntPtr value = intPtr;
			OdFdFieldEvaluator result;
			try
			{
				OdFdFieldEvaluator odFdFieldEvaluator = (OdFdFieldEvaluator)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdFdFieldEngine_findEvaluator(this.swigCPtr, OdDbField.getCPtr(pField), ref intPtr), false);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				result = odFdFieldEvaluator;
			}
			finally
			{
				if (intPtr != value)
				{
					pszEvalId = Marshal.PtrToStringUni(intPtr);
				}
			}
			return result;
		}

		public virtual void addFieldReactor(OdFdFieldReactor pReactor)
		{
			TD_DbPINVOKE.OdFdFieldEngine_addFieldReactor(this.swigCPtr, OdFdFieldReactor.getCPtr(pReactor));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void removeFieldReactor(OdFdFieldReactor pReactor)
		{
			TD_DbPINVOKE.OdFdFieldEngine_removeFieldReactor(this.swigCPtr, OdFdFieldReactor.getCPtr(pReactor));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
